package edu.ustb.controller;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;

import edu.ustb.domain.Goods;
import edu.ustb.service.GoodsService;
import edu.ustb.service.GoodsServiceImpl;

/**
 * Servlet implementation class GoodsDetailController
 */
@WebServlet("/goods/detail.do")
public class GoodsDetailController extends HttpServlet {

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		
		String goodsId = request.getParameter("goodsId");
		System.out.println("get goodsId = "+ goodsId);
		try {
			GoodsService goodsService = new GoodsServiceImpl();
			Goods goods = goodsService.findGoodsByGoodsId(goodsId);
			response.getWriter().print(JSON.toJSONString(goods));
			System.out.println(goods);
			//request.setAttribute("goods", goods);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
